package com.example.voluntary.mapper;

import com.example.voluntary.domain.po.VolunteerParticipation;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface VolunteerParticipationMapper {
    /**
     * 查询用户是否已经参与过该活动
     * @param activityId 活动ID
     * @param currentId 当前用户ID
     */
   @Select("SELECT count(activity_id) FROM volunteer_participation WHERE activity_id = #{activityId} AND user_id = #{currentId}")
    Integer selectParticipation(Integer activityId, Long currentId);

   /**
     * 插入用户参与记录
     * @param volunteerParticipation 参与记录
     */
   @Insert("INSERT INTO volunteer_participation (activity_id, user_id," +
           "duration, participation_status, created_at, updated_at) " +
           "VALUES (#{activityId}, #{userId}, #{duration}, #{participationStatus}, #{createdAt}, #{updatedAt})")
    void insert(VolunteerParticipation volunteerParticipation);


   /**
     * 根据活动id查询用户id
     * @param activityId 活动id
     * @return 用户id列表
     */
   @Select("SELECT user_id FROM volunteer_participation WHERE activity_id = #{activityId}")
    List<Long> selectUserIdByActivityId(Integer activityId);

   /**
     * 根据活动id和用户id查询用户参与状态
     * @param activityId 活动id
     * @param currentId 当前用户id
     * @return 用户参与状态
     */
   @Select("SELECT participation_status FROM volunteer_participation WHERE activity_id = #{activityId} AND user_id = #{currentId}")
    Integer selectParticipationStatus(Integer activityId, Long currentId);

   /**
     * 更新用户参与记录
     * @param participation 用户参与记录
     */
    void updateActivity(VolunteerParticipation participation);

    VolunteerParticipation selectByActivityIdAndUserId(@Param("activityId") Integer activityId, @Param("currentId") Long currentId);
}
